Function Str2Key(const k:string):integer;
var key:string;
begin
key:=UpperCase(k);
  if key = 'BACKSPACE' then result := 8 else
  if key = 'TAB' then result := 9 else
  if key = 'CLEAR' then result := 12 else
  if key = 'RETURN' then result := 13 else
  if key = 'PAUSE' then result := 19 else
  if key = 'ESCAPE' then result := 27 else
  if key = 'SPACE' then result := 32 else
  if key = 'EXCLAIM' then result := 33 else
  if key = 'QUOTEDBL' then result := 34 else
  if key = 'HASH' then result := 35 else
  if key = 'DOLLAR' then result := 36 else
  if key = 'AMPERSAND' then result := 38 else
  if key = 'QUOTE' then result := 39 else
  if key = 'LEFTPAREN' then result := 40 else
  if key = 'RIGHTPAREN' then result := 41 else
  if key = 'ASTERISK' then result := 42 else
  if key = 'PLUS' then result := 43 else
  if key = 'COMMA' then result := 44 else
  if key = 'MINUS' then result := 45 else
  if key = 'PERIOD' then result := 46 else
  if key = 'SLASH' then result := 47 else
  if key = '0' then result := 48 else
  if key = '1' then result := 49 else
  if key = '2' then result := 50 else
  if key = '3' then result := 51 else
  if key = '4' then result := 52 else
  if key = '5' then result := 53 else
  if key = '6' then result := 54 else
  if key = '7' then result := 55 else
  if key = '8' then result := 56 else
  if key = '9' then result := 57 else
  if key = 'COLON' then result := 58 else
  if key = 'SEMICOLON' then result := 59 else
  if key = 'LESS' then result := 60 else
  if key = 'EQUALS' then result := 61 else
  if key = 'GREATER' then result := 62 else
  if key = 'QUESTION' then result := 63 else
  if key = 'AT' then result := 64 else
  { Skip uppercase letters }
  if key = 'LEFTBRACKET' then result := 91 else
  if key = 'BACKSLASH' then result := 92 else
  if key = 'RIGHTBRACKET' then result := 93 else
  if key = 'CARET' then result := 94 else
  if key = 'UNDERSCORE' then result := 95 else
  if key = 'BACKQUOTE' then result := 96 else
  if key = 'A' then result := 97 else
  if key = 'B' then result := 98 else
  if key = 'C' then result := 99 else
  if key = 'D' then result := 100 else
  if key = 'E' then result := 101 else
  if key = 'F' then result := 102 else
  if key = 'G' then result := 103 else
  if key = 'H' then result := 104 else
  if key = 'I' then result := 105 else
  if key = 'J' then result := 106 else
  if key = 'K' then result := 107 else
  if key = 'L' then result := 108 else
  if key = 'M' then result := 109 else
  if key = 'N' then result := 110 else
  if key = 'O' then result := 111 else
  if key = 'P' then result := 112 else
  if key = 'Q' then result := 113 else
  if key = 'R' then result := 114 else
  if key = 'S' then result := 115 else
  if key = 'T' then result := 116 else
  if key = 'U' then result := 117 else
  if key = 'V' then result := 118 else
  if key = 'W' then result := 119 else
  if key = 'X' then result := 120 else
  if key = 'Y' then result := 121 else
  if key = 'Z' then result := 122 else
  if key = 'DELETE' then result := 127 else
  // End of ASCII mapped keysyms
  // International keyboard syms
  if key = 'WORLD_0' then result := 160 else // 0xA0
  if key = 'WORLD_1' then result := 161 else
  if key = 'WORLD_2' then result := 162 else
  if key = 'WORLD_3' then result := 163 else
  if key = 'WORLD_4' then result := 164 else
  if key = 'WORLD_5' then result := 165 else
  if key = 'WORLD_6' then result := 166 else
  if key = 'WORLD_7' then result := 167 else
  if key = 'WORLD_8' then result := 168 else
  if key = 'WORLD_9' then result := 169 else
  if key = 'WORLD_10' then result := 170 else
  if key = 'WORLD_11' then result := 171 else
  if key = 'WORLD_12' then result := 172 else
  if key = 'WORLD_13' then result := 173 else
  if key = 'WORLD_14' then result := 174 else
  if key = 'WORLD_15' then result := 175 else
  if key = 'WORLD_16' then result := 176 else
  if key = 'WORLD_17' then result := 177 else
  if key = 'WORLD_18' then result := 178 else
  if key = 'WORLD_19' then result := 179 else
  if key = 'WORLD_20' then result := 180 else
  if key = 'WORLD_21' then result := 181 else
  if key = 'WORLD_22' then result := 182 else
  if key = 'WORLD_23' then result := 183 else
  if key = 'WORLD_24' then result := 184 else
  if key = 'WORLD_25' then result := 185 else
  if key = 'WORLD_26' then result := 186 else
  if key = 'WORLD_27' then result := 187 else
  if key = 'WORLD_28' then result := 188 else
  if key = 'WORLD_29' then result := 189 else
  if key = 'WORLD_30' then result := 190 else
  if key = 'WORLD_31' then result := 191 else
  if key = 'WORLD_32' then result := 192 else
  if key = 'WORLD_33' then result := 193 else
  if key = 'WORLD_34' then result := 194 else
  if key = 'WORLD_35' then result := 195 else
  if key = 'WORLD_36' then result := 196 else
  if key = 'WORLD_37' then result := 197 else
  if key = 'WORLD_38' then result := 198 else
  if key = 'WORLD_39' then result := 199 else
  if key = 'WORLD_40' then result := 200 else
  if key = 'WORLD_41' then result := 201 else
  if key = 'WORLD_42' then result := 202 else
  if key = 'WORLD_43' then result := 203 else
  if key = 'WORLD_44' then result := 204 else
  if key = 'WORLD_45' then result := 205 else
  if key = 'WORLD_46' then result := 206 else
  if key = 'WORLD_47' then result := 207 else
  if key = 'WORLD_48' then result := 208 else
  if key = 'WORLD_49' then result := 209 else
  if key = 'WORLD_50' then result := 210 else
  if key = 'WORLD_51' then result := 211 else
  if key = 'WORLD_52' then result := 212 else
  if key = 'WORLD_53' then result := 213 else
  if key = 'WORLD_54' then result := 214 else
  if key = 'WORLD_55' then result := 215 else
  if key = 'WORLD_56' then result := 216 else
  if key = 'WORLD_57' then result := 217 else
  if key = 'WORLD_58' then result := 218 else
  if key = 'WORLD_59' then result := 219 else
  if key = 'WORLD_60' then result := 220 else
  if key = 'WORLD_61' then result := 221 else
  if key = 'WORLD_62' then result := 222 else
  if key = 'WORLD_63' then result := 223 else
  if key = 'WORLD_64' then result := 224 else
  if key = 'WORLD_65' then result := 225 else
  if key = 'WORLD_66' then result := 226 else
  if key = 'WORLD_67' then result := 227 else
  if key = 'WORLD_68' then result := 228 else
  if key = 'WORLD_69' then result := 229 else
  if key = 'WORLD_70' then result := 230 else
  if key = 'WORLD_71' then result := 231 else
  if key = 'WORLD_72' then result := 232 else
  if key = 'WORLD_73' then result := 233 else
  if key = 'WORLD_74' then result := 234 else
  if key = 'WORLD_75' then result := 235 else
  if key = 'WORLD_76' then result := 236 else
  if key = 'WORLD_77' then result := 237 else
  if key = 'WORLD_78' then result := 238 else
  if key = 'WORLD_79' then result := 239 else
  if key = 'WORLD_80' then result := 240 else
  if key = 'WORLD_81' then result := 241 else
  if key = 'WORLD_82' then result := 242 else
  if key = 'WORLD_83' then result := 243 else
  if key = 'WORLD_84' then result := 244 else
  if key = 'WORLD_85' then result := 245 else
  if key = 'WORLD_86' then result := 246 else
  if key = 'WORLD_87' then result := 247 else
  if key = 'WORLD_88' then result := 248 else
  if key = 'WORLD_89' then result := 249 else
  if key = 'WORLD_90' then result := 250 else
  if key = 'WORLD_91' then result := 251 else
  if key = 'WORLD_92' then result := 252 else
  if key = 'WORLD_93' then result := 253 else
  if key = 'WORLD_94' then result := 254 else
  if key = 'WORLD_95' then result := 255 else // 0xFF
  // Numeric keypad
  if key = 'KP0' then result := 256 else
  if key = 'KP1' then result := 257 else
  if key = 'KP2' then result := 258 else
  if key = 'KP3' then result := 259 else
  if key = 'KP4' then result := 260 else
  if key = 'KP5' then result := 261 else
  if key = 'KP6' then result := 262 else
  if key = 'KP7' then result := 263 else
  if key = 'KP8' then result := 264 else
  if key = 'KP9' then result := 265 else
  if key = 'KP_PERIOD' then result := 266 else
  if key = 'KP_DIVIDE' then result := 267 else
  if key = 'KP_MULTIPLY' then result := 268 else
  if key = 'KP_MINUS' then result := 269 else
  if key = 'KP_PLUS' then result := 270 else
  if key = 'KP_ENTER' then result := 271 else
  if key = 'KP_EQUALS' then result := 272 else
  // Arrows + Home/End pad
  if key = 'UP' then result := 273 else
  if key = 'DOWN' then result := 274 else
  if key = 'RIGHT' then result := 275 else
  if key = 'LEFT' then result := 276 else
  if key = 'INSERT' then result := 277 else
  if key = 'HOME' then result := 278 else
  if key = 'END' then result := 279 else
  if key = 'PAGEUP' then result := 280 else
  if key = 'PAGEDOWN' then result := 281 else
  // Function keys
  if key = 'F1' then result := 282 else
  if key = 'F2' then result := 283 else
  if key = 'F3' then result := 284 else
  if key = 'F4' then result := 285 else
  if key = 'F5' then result := 286 else
  if key = 'F6' then result := 287 else
  if key = 'F7' then result := 288 else
  if key = 'F8' then result := 289 else
  if key = 'F9' then result := 290 else
  if key = 'F10' then result := 291 else
  if key = 'F11' then result := 292 else
  if key = 'F12' then result := 293 else
  if key = 'F13' then result := 294 else
  if key = 'F14' then result := 295 else
  if key = 'F15' then result := 296 else
  // Key state modifier keys
  if key = 'NUMLOCK' then result := 300 else
  if key = 'CAPSLOCK' then result := 301 else
  if key = 'SCROLLOCK' then result := 302 else
  if key = 'RSHIFT' then result := 303 else
  if key = 'LSHIFT' then result := 304 else
  if key = 'RCTRL' then result := 305 else
  if key = 'LCTRL' then result := 306 else
  if key = 'RALT' then result := 307 else
  if key = 'LALT' then result := 308 else
  if key = 'RMETA' then result := 309 else
  if key = 'LMETA' then result := 310 else
  if key = 'LSUPER' then result := 311 else // Left "Windows" key
  if key = 'RSUPER' then result := 312 else // Right "Windows" key
  if key = 'MODE' then result := 313 else // "Alt Gr" key
  if key = 'COMPOSE' then result := 314 else // Multi-key compose key
  // Miscellaneous function keys
  if key = 'HELP' then result := 315 else
  if key = 'PRINT' then result := 316 else
  if key = 'SYSREQ' then result := 317 else
  if key = 'BREAK' then result := 318 else
  if key = 'MENU' then result := 319 else
  if key = 'POWER' then result := 320 else // Power Macintosh power key
  if key = 'EURO' then result := 321 else // Some european keyboards
result:=0;
end;
